package com.iuschool.controller;

import com.iuschool.service.WelcomeService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;

/**
 * @author max
 * @version 1.0.0
 * @ClassName WelcomeController.java
 * @createTime 2020年09月17日 17:29:00
 */
@Controller
public class AwareController implements BeanNameAware, ApplicationContextAware {
	private String myBeanName;
	private ApplicationContext myContainer;

	public void handleRequest() {
		System.out.println("我的bean name: " + myBeanName);
		for (String each : myContainer.getBeanDefinitionNames()) {
			System.out.println("获取到容器中的 bean name: " + each);
		}
	}

	@Override
	public void setBeanName(String name) {
		myBeanName = name;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		myContainer = applicationContext;
	}
}
